﻿
using Xacml.Core;
using Xacml.Core.Interfaces;
using System.Collections;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class ApplyElement : ApplyBaseReadWrite, IExpression
  {
    public override bool IsReadOnly
    {
      get
      {
        return false;
      }
    }

    public ApplyElement(XmlReader reader, XacmlVersion version)
      : base(reader, "Apply", version)
    {
    }

    public ApplyElement(string functionId, IExpressionCollectionReadWrite arguments, XacmlVersion schemaVersion)
      : base(functionId, arguments, schemaVersion)
    {
    }

    public override void WriteDocument(XmlWriter writer)
    {
      writer.WriteStartElement("Apply");
      if (this.FunctionId != null)
        writer.WriteAttributeString("FunctionId", this.FunctionId);
      foreach (IExpression expression in (CollectionBase) this.Arguments)
        expression.WriteDocument(writer);
      writer.WriteEndElement();
    }
  }
}
